package com.evl.task;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.evl.common.constant.OrderConst;
import com.evl.common.persistence.dao.TrainOrderMapper;
import com.evl.common.persistence.model.TrainOrder;
import com.evl.trainOrder.service.ITrainOrderService;

/**
 * 定时刷新订单支付状态
 * @author dangsheng
 *
 */
@Component
public class OrderPayStatusRefreshTask {
	
	@Resource
	private ITrainOrderService	iTrainOrderService;
	
	@Resource
	private TrainOrderMapper	trainOrderMapper;
	
	private Logger log = Logger.getLogger(this.getClass());
	
	@Scheduled(cron="0 0/2 * * * ?") //间隔2分钟执行
	public void refreshOrder(){
		log.info("====================定时刷新支付状态=================");
		TrainOrder order = new TrainOrder();
		order.setOrderStatus(OrderConst.STS_SYS_PAYING);
		List<TrainOrder> list = trainOrderMapper.selectTrainOrderList(order);
		for(TrainOrder odr: list){
			try {
				iTrainOrderService.refushOrderPayStatus(odr.getOrderNo());
			} catch (Exception e) {
				log.error("订单号["+odr.getOrderNo()+"]刷新支付状态异常;"+e.getMessage());
			}
		}
		log.info("====================定时刷新支付状态完成=================");
	}
}
